package com.ljl.task;

import cn.hutool.core.thread.ThreadUtil;
import com.ljl.entity.Account;
import com.ljl.service.AccountService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author 刘家良
 * @date 2022/09/11 22:47
 * @description
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class SignInTask {

    private final AccountService accountService;

    @Scheduled(cron = "0 0 7 * * ?")
    public void run() {
        List<Account> accounts = accountService.queryAll();
        for (Account account : accounts) {
            Long id = account.getId();
            try {
                accountService.signInByAccountId(id);
                ThreadUtil.sleep(3, TimeUnit.MINUTES);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
